package test;

import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.regex.*;

public class AddFormBean {

    public String custid;
    public String acc;
    public String atype;
    public Hashtable errors;
    public DbConnect dbc;

    public boolean validate() {
        boolean bool = true;

        if (acc.equals("")) {
            errors.put("acc", "Please enter Account Name");
            acc = "";
            bool = false;
        }
        if (atype.equals("")) {
            errors.put("atype", "Please enter Account type");
            atype = "";
            bool = false;
        }


        return bool;
    }

    public String getErrorMsg(String s) {
        String errorMsg = (String) errors.get(s.trim());
        return (errorMsg == null) ? "" : errorMsg;
    }

    public AddFormBean() {

        acc = "";
        atype = "";

        errors = new Hashtable();
    }

    public String getAcc() {
        return acc;
    }

    public String getAtype() {
        return atype;
    }

    public void setAcc(String a) {

        acc = a;
    }

    public void setAtype(String a) {

        atype = a;
    }

    public boolean match() {

        boolean flag = false;
        Connection con = null;

        dbc = new DbConnect();
        String sequence2 = null;
        String sequence3 = null;
        int ff, billstat, bal, defstat;
        try {

            con = dbc.getOracleConnection();
            Statement st = con.createStatement();
            PreparedStatement seq_ps = con.prepareStatement("select seq_custid.nextval,seq_accno.nextval,seq_bill.nextval from dual");
            ResultSet seq_rs = seq_ps.executeQuery();

            while (seq_rs.next()) {
                sequence2 = seq_rs.getString(2);
                sequence3 = seq_rs.getString(3);
            }
            ff = 0;
            billstat = 0;
            bal = 10000;
            defstat = 1;
            st.executeUpdate("insert into onbill_billstatus values(" + "'" + sequence2 + "'" + "," + "'" + billstat + "'" + ")");
            st.executeUpdate("insert into onbill_account values(" + "'" + custid + "'" + "," + "'" + sequence3 + "'," + "'" + acc + "'" + "," + "'" + atype + "'" + "," + "'" + bal + "'" + "," + "'" + defstat + "'" + "," + "'" + sequence2 + "'" + ")");




            flag = true;








        } catch (Exception e) {
            e.printStackTrace();
        }

        return flag;
    }
}
